package com.example.helloworld;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.View;

import com.example.helloworld.adapter.RecordPagerAdapter;
import com.example.helloworld.frag_record.IncomeFragment;
import com.example.helloworld.frag_record.BaseRecordFragment;
import com.example.helloworld.frag_record.OutcomeFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class RecordActivity extends AppCompatActivity {
    TabLayout tabLayout;
    ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        //1.查找控件
        tabLayout=findViewById(R.id.main2_tab);
        viewPager=findViewById(R.id.main2_viewpager);
        //2.给viewpager设置加载哪些fragment
        initPager();
    }

    private void initPager() {
        //初始化Viewpager里面两个fragment的集合
        List<Fragment>fragmentList=new ArrayList<>();
        //创建收入和支出界面放置在fragment当中
        OutcomeFragment outFrag = new OutcomeFragment();//支出
        IncomeFragment inFrag = new IncomeFragment();//收入
        fragmentList.add(outFrag);
        fragmentList.add(inFrag);//先支出后收入
        //创建适配器
        RecordPagerAdapter pagerAdapter = new RecordPagerAdapter(getSupportFragmentManager(), fragmentList);
        //设置适配器
        viewPager.setAdapter(pagerAdapter);
        //将tablayout和ViewPager进行关联
        tabLayout.setupWithViewPager(viewPager);
    }

    public void onClick(View view) {//点击事件
        switch (view.getId()) {
            case R.id.main2_back:
            finish();
            break;
        }

    }
}
